package com.common.auth;

import java.util.Date;
import java.util.List;

import com.common.mybatis.gen.model.SysFunc;
import com.common.mybatis.gen.model.SysRole;

/**
 * 自定义认证信息类
 * @author guanghong.ji
 * @date   2018年6月8日
 */
public class MyAuthenticationInfo {

	/**
	 * 是否认证过
	 */
	private Boolean authenticated = false;
	private Integer userId;
	/**
	 * 用户认证后的token
	 */
	private String token;
	/**
	 * token创建时间
	 */
	private Date tokenCreateTime;
	/**
	 * token过期时间<br>
	 * （token每次使用后都会刷新，过期时间后延，可设置超过多长时间不刷新即过期）
	 */
	private Date tokenExpireTime;
	/**
	 * 用户角色
	 */
	private List<SysRole> roles;
	/**
	 * 用户有权限的功能列表
	 */
	private List<SysFunc> funcs;
	
	public Boolean getAuthenticated() {
		return authenticated;
	}
	public void setAuthenticated(Boolean authenticated) {
		this.authenticated = authenticated;
	}
	public Integer getUserId() {
		return userId;
	}
	public void setUserId(Integer userId) {
		this.userId = userId;
	}
	public String getToken() {
		return token;
	}
	public void setToken(String token) {
		this.token = token;
	}
	public Date getTokenCreateTime() {
		return tokenCreateTime;
	}
	public void setTokenCreateTime(Date tokenCreateTime) {
		this.tokenCreateTime = tokenCreateTime;
	}
	public Date getTokenExpireTime() {
		return tokenExpireTime;
	}
	public void setTokenExpireTime(Date tokenExpireTime) {
		this.tokenExpireTime = tokenExpireTime;
	}
	public void freshTokenExpireTime(Long expireTimeLong) {
		if(expireTimeLong == null) expireTimeLong = 86400L;
		if(this.tokenExpireTime == null) {
			if(this.tokenCreateTime != null)
			this.tokenExpireTime = new Date(this.tokenCreateTime.getTime() + expireTimeLong);
		}
		else {
			this.tokenExpireTime = new Date(new Date().getTime() + expireTimeLong);
		}
	}
	public List<SysRole> getRoles() {
		return roles;
	}
	public void setRoles(List<SysRole> roles) {
		this.roles = roles;
	}
	public List<SysFunc> getFuncs() {
		return funcs;
	}
	public void setFuncs(List<SysFunc> funcs) {
		this.funcs = funcs;
	}
	
}
